<?php

/**
 * \file
 * Classe `WheelColorPicker`.
 */

namespace pilar\AdvancedFormMembers /* \cond */ ; /* \endcond */
{

// Utilisation de la librairie javascript du color-picker:
 global $pJS, $pCSS;
 $pJS[] = '/js/farbtastic/farbtastic.js';
 $pCSS[] = '/js/farbtastic/farbtastic.css';

/**
 * Membre WheelColorPicker.
 *
 * \since 09/12/2008
 * \author Matthieu OVIEDO <matthieu.oviedo@gmail.com>
 */
class WheelColorPicker extends \pilar\SimpleFormMembers\Textbox {

protected function loadDefaultParams() {
 parent::loadDefaultParams();

 $this->params->set(array(
  'size' => 7,
  'maxLength' => 7
 ));
}


public function guiDomNode($domDoc) {
 $domGui = parent::guiDomNode($domDoc);

 $domPicker = $domDoc->createElement('div', '@');
 $domPicker->setAttribute('id', $this->globalId('picker'));
 $domPicker->setAttribute('class', 'wheelColorPicker');

 $domGui->appendChild($domPicker);

 return $domGui;
}


protected function outputGuiController() {
 parent::outputGuiController();
?>
<?php if($this->value() == '') { ?>
$('#<?php echo $this->globalId() ?>').val('#');
<?php } ?>
$('#<?php echo $this->globalId('picker') ?>').farbtastic('#<?php echo $this->globalId() ?>');
$('#<?php echo $this->globalId() ?>').focus(function() {
 $('#<?php echo $this->globalId('picker') ?>').addClass('wheelColorPicker_selected');
}).blur(function(){
 $('#<?php echo $this->globalId('picker') ?>').removeClass('wheelColorPicker_selected');
});
<?php
}

} // Class.

} // Namespace.

?>
